package com.xdcplus.web.controller;



import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.exceptions.domain.ResponseVO;

import com.xdcplus.pager.vo.PageVO;
import com.xdcplus.web.common.pojo.dto.ToolProductionLineMainDTO;
import com.xdcplus.web.common.pojo.dto.ToolProductionLineMainFilterDTO;
import com.xdcplus.web.common.pojo.vo.*;
import com.xdcplus.web.service.ToolProductionLineMainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Validation;
import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * (ToolProductionLineMain)表服务控制层
 *
 * @author Man.Chen
 * @since 2024-12-03 16:38:52
 */
@Api(tags = "(ToolProductionLineMain)") 
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("toolProductionLineMain")
public class ToolProductionLineMainController extends AbstractController {

    @Autowired
    private ToolProductionLineMainService toolProductionLineMainService;


    @ApiOperation("新增")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveToolProductionLineMain(@RequestBody ToolProductionLineMainDTO toolProductionLineMainDTO) {

        log.info("saveToolProductionLineMain {}", toolProductionLineMainDTO.toString());

        toolProductionLineMainDTO.setCreatedUser(getAccount());
        toolProductionLineMainService.saveToolProductionLineMain(toolProductionLineMainDTO);

        return ResponseVO.success();
    }

    @ApiOperation("修改")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateToolProductionLineMain(@RequestBody ToolProductionLineMainDTO toolProductionLineMainDTO) {

        log.info("updateToolProductionLineMain {}", toolProductionLineMainDTO.toString());

        toolProductionLineMainDTO.setUpdatedUser(getAccount());
        toolProductionLineMainService.updateToolProductionLineMain(toolProductionLineMainDTO);

        return ResponseVO.success();
    }

    @ApiOperation("删除")
    @DeleteMapping(value = "/{toolProductionLineMainId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "toolProductionLineMainId", dataTypeClass = Long.class, value = "ID", required = true),
    })
    public ResponseVO deleteToolProductionLineMainLogical(@PathVariable("toolProductionLineMainId")
                                         @NotNull(message = "ID不能为空") Long toolProductionLineMainId) {

        log.info("deleteToolProductionLineMainLogical {}", toolProductionLineMainId);

        toolProductionLineMainService.deleteToolProductionLineMainLogical(toolProductionLineMainId);

        return ResponseVO.success();
    }
    
    @ApiOperation("批量删除")
    @DeleteMapping(value = "/deleteByIds/{toolProductionLineMainIds}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "toolProductionLineMainId", dataTypeClass = Long.class, value = "ID", required = true),
    })
    public ResponseVO deleteToolProductionLineMainLogical(@PathVariable("toolProductionLineMainIds")
                                         @NotNull(message = "ID不能为空") String toolProductionLineMainIds) {

        log.info("deleteToolProductionLineMainByIds {}", toolProductionLineMainIds);

        toolProductionLineMainService.deleteToolProductionLineMainByIds(toolProductionLineMainIds);

        return ResponseVO.success();
    }

    @ApiOperation("查询")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<PageVO<ToolProductionLineMainVO>> findToolProductionLineMain(ToolProductionLineMainFilterDTO toolProductionLineMainFilterDTO) {

        log.info("findToolProductionLineMain {}", toolProductionLineMainFilterDTO);

        Validation.buildDefaultValidatorFactory().getValidator().validate(toolProductionLineMainFilterDTO);

        return ResponseVO.success(toolProductionLineMainService.queryToolProductionLineMain(toolProductionLineMainFilterDTO));
    }


    @ApiOperation("新增研发线")
    @PostMapping("/addProductionLine")
    public ResponseVO<Long> addProductionLine(@RequestBody ToolProductionLineMainVO productionLineMainVO) {
        log.info("findToolProductionLineMain {}", productionLineMainVO);
        return ResponseVO.success(toolProductionLineMainService.addProductionLine(productionLineMainVO));
    }

    @ApiOperation("查询研发线")
    @PostMapping("/findProductionLine")
    public ResponseVO<List<ToolProductionLineMainVO>> findProductionLine(
           @RequestBody ToolProductionLineMainDTO toolProductionLineMainDTO) {
        log.info("findProductionLineBySpecAndDate {}", toolProductionLineMainDTO);
        return ResponseVO.success(toolProductionLineMainService.findProductionLine(toolProductionLineMainDTO));
    }


    @ApiOperation("修改研发线")
    @PostMapping("/updateProductionLineById")
    public ResponseVO updateProductionLineById(@RequestBody ToolProductionLineMainVO toolProductionLineMainVO) {
        log.info("updateProductionLineById {}", toolProductionLineMainVO);
        toolProductionLineMainService.updateProductionLineById(toolProductionLineMainVO);
        return ResponseVO.success();
    }

    @ApiOperation("删除研发线")
    @GetMapping("/deleteProductionLineById")
    public ResponseVO deleteProductionLineById(Long id) {
        log.info("deleteProductionLineById {}", id);
        toolProductionLineMainService.deleteProductionLineById(id);
        return ResponseVO.success();
    }

    @ApiOperation("研发线状态变更")
    @GetMapping(value = "updateProductionLineByIdAndStatus", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateProductionLineByIdAndStatus(Long id,Long status) {

        log.info("updateProductionLineByIdAndStatus {}", id, status);
        toolProductionLineMainService.updateProductionLineByIdAndStatus(id,status);
        return ResponseVO.success();
    }


    @ApiOperation("查询工艺参数采集")
    @GetMapping("/queryLineOrderTargetList")
    public ResponseVO<PageVO<CraftCheckOrderTargetVO>> queryLineOrderTargetList(Long id) {

        log.info("findCraftCheckOrderTarget {}", id);
        return ResponseVO.success(toolProductionLineMainService.queryLineOrderTargetList(id));
    }


    @ApiOperation("查询点检工单点检项明细表")
    @GetMapping(value = "queryLineCraftCheckOrderItems", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<PageVO<CraftCheckOrderItemsVO>> queryLineCraftCheckOrderItems(Long id) {

        log.info("findCraftCheckOrderItems {}", id);
        return ResponseVO.success(toolProductionLineMainService.queryLineCraftCheckOrderItems(id));
    }


    @ApiOperation("查询spc数据")
    @GetMapping(value = "queryLineSpcData", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<List<ToolProductionDataItemVO>> queryLineSpcData(Long id){
        return ResponseVO.success(toolProductionLineMainService.queryLineSpcData(id));

    }

    @ApiOperation("查询spc控制图")
    @PostMapping(value = "queryLineSpcControlChart")
    public ResponseVO<List<ToolProductionDataVO>> queryLineSpcControlChart(@RequestBody ToolProductionControlVO toolProductionControlVO){
        return ResponseVO.success(toolProductionLineMainService.queryLineSpcControlChart(toolProductionControlVO));

    }

    @ApiOperation("查询点检和SPC")
    @GetMapping(value = "queryLineCraftCheckOrderItemsAndSpc", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<ToolProductionDjAndSpcVO> queryLineCraftCheckOrderItemsAndSpc(Long id) {
        return ResponseVO.success(toolProductionLineMainService.queryLineCraftCheckOrderItemsAndSpc(id));

    }

    @ApiOperation("查询电性能报表")
    @GetMapping(value = "queryElectricityPerformanceReport", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<ToolDmIvSummaryVO> queryElectricityPerformanceReport(Long id) {
        return ResponseVO.success(toolProductionLineMainService.queryElectricityPerformanceReport(id));

    }





}
